//
//  FANTabBar.m
//  Weibo - OC
//
//  Created by user on 16/4/17.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANTabBar.h"

//#warning 宏定义一定要放到 导入头文件的 上面, 会影响编译

//define this constant if you want to use Masonry without the 'mas_' prefix

#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax

#define MAS_SHORTHAND_GLOBALS

#import <Masonry/Masonry.h>



@interface FANTabBar ()

@property (nonatomic, strong) UIButton *addButton;


@end

@implementation FANTabBar

- (UIButton *)addButton{
    
    if (!_addButton) {
        
        _addButton = [[UIButton alloc] init];
        
        [_addButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [_addButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        
        [_addButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [_addButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        
        [_addButton addTarget:self action:@selector(didClickButton) forControlEvents:UIControlEventTouchUpInside];
        
        [_addButton sizeToFit];
    }
    
    return _addButton;
}

- (void)didClickButton{
    
    self.backBlock();
}

- (instancetype)init{
    
    if (self = [super init]){
        
//        NSLog(@"hahahaha");
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    [self addSubview:self.addButton];

}

- (void)layoutSubviews{
    
    [super layoutSubviews];

    
    self.addButton.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    
    CGFloat kWidth = [UIScreen mainScreen].bounds.size.width/5;
    
    __block int index = 0;
    
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
       
        if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            
            obj.frame = CGRectMake(index*kWidth, 0, kWidth, self.frame.size.height);
            
            index++;
            
            if (index == 2) {
                
                index++;
            }
            
        }
        
    }];
    

}



@end
